package com.css.dzj.dzjap.modules.lawenforcesuper.controller;


import com.css.aq.server.service.BaseService;
import com.css.dzj.dzjap.common.util.R;
import com.css.dzj.dzjap.modules.info.entity.ApExpertEntity;
import com.css.dzj.dzjap.modules.lawenforcesuper.entity.ApExpertRegulatorInfoEntity;
import com.css.dzj.dzjap.modules.lawenforcesuper.service.ApExpertRegulatorService;
import com.css.dzj.dzjap.modules.lawenforcesuper.service.ExpregulatConnectExpertService;
import com.css.dzj.dzjap.modules.lawenforcesuper.view.ExtractExpertView;
import com.querydsl.core.QueryResults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.*;

/**
 * 监管专家关联专家controller
 * @author liyunyue
 */
@RequestMapping("/connectExpert")
@RestController
public class ExpregulatConnectExpertController {

    @Autowired
    private ExpregulatConnectExpertService connectExpertService;

    @Autowired
    private ApExpertRegulatorService regulatorService;
    @Autowired
    BaseService baseService;
    /**
     * 通过监管任务Id分页查询专家list
     * @param regulatId
     * @param pageNo
     * @param pageSize
     * @return
     */
    @PostMapping("/queryByRegulateId")
    public R queryExpertByRegulatId(@RequestParam(required = false) String regulatId,
                                    @RequestParam(required = false, defaultValue = "1") Integer pageNo,
                                    @RequestParam(required = false, defaultValue = "10") Integer pageSize) {
        try {
            PageRequest pageRequest = PageRequest.of(pageNo-1, pageSize);
            ApExpertRegulatorInfoEntity regulatorInfoEntity = regulatorService.queryById(regulatId);
            QueryResults<ApExpertEntity> extractExpertList = connectExpertService.queryExpertByRegulateId(pageRequest, regulatId);
            baseService.logSuccess(3,"查询成功","2");
            return R.ok().put("data", extractExpertList).put("expertExtract", regulatorInfoEntity);
        } catch(Exception e) {
            baseService.logFailed(3,"查询失败","2");
            return R.error(e.getMessage());
        }

    }

}
